1. Technical Field
The present invention relates to multiprocessor systems in general, and in particular to memory controllers for multiprocessor systems. Still more particularly, the present invention relates to a method and apparatus for supporting low-overhead memory locks within a multiprocessor system.
2. Description of Related Art
A multiprocessor system typically requires a mechanism for synchronizing operations of various processors within the multiprocessor system in order to allow interactions among those processors that work on a task. Thus, the instruction set of processors within a multiprocessor system are commonly equipped with explicit instructions for handling task synchronization. For example, the instruction set of PowerPC® processors, which are manufactured by International Business Machines Corporation of Armonk, N.Y., provides instructions such as lwarx or ldwarx and stwcx or stdwx (hereafter referred to as larx and stcx, respectively) for building synchronization primitives.
The larx instruction loads an aligned word of memory into a register within a processor. In addition, the larx instruction places a “reservation” on the block of memory that contains the word of memory accessed. The reservation contains the address of the memory block and a flag. The flag is made active, and the address of the memory block is loaded when a larx instruction successfully reads the word of memory referenced. If the reservation is valid (i.e., the flag is active), the processor and the memory hierarchy are obligated to monitor the entire processing system cooperatively for any operation that attempts to write to the memory block at which the reservation exists.
The reservation flag is used to control the behavior of a stcx instruction that is the counterpart to the larx instruction. The stcx instruction first determines if the reservation flag is valid. If so, the stcx instruction performs a Store to the word of memory specified, sets a condition code register to indicate that the Store has succeeded, and resets the reservation flag. If, on the other hand, the reservation flag in the reservation is not valid, the stcx instruction does not perform a Store to the word of memory and sets a condition code register indicating that the Store has failed. The stcx instruction is often referred to as a “Conditional Store” due to the fact that the Store is conditional on the status of the reservation flag.
The general concept underlying the larx/stcx instruction sequence is to allow a processor to read a memory location, to modify the memory location in some way, and to store the new value to the memory location while ensuring that no other processor within a multiprocessor system has altered the memory location from the point in time when the larx instruction was executed until the stcx instruction completes. Such a sequence is usually referred to as an “atomic read-modify-write” sequence because a processor was able to read a memory location, modify a value within the memory location, and then write a new value without any interruption by another processor writing to the same memory location. The larx/stcx sequence of operations do not occur as one uninterruptable sequence, but rather, the fact that the processor is able to execute a larx instruction and then later successfully complete the stcx instruction ensures a programmer that the read/modify/write sequence did, in fact, occur as if it were atomic. This atomic property of a larx/stcx sequence can be used to implement a number of synchronization primitives well-known to those skilled in the art.
The larx/stcx sequence of operations work well with cache memories that are in close proximity with processors. However, the larx/stcx sequence of operations are not efficient for accessing a system memory, especially when many processors, which are located relatively far away from the system memory, are attempting to access the same memory block. Consequently, it would be desirable to provide a method and apparatus for supporting low-overhead memory locks for a system memory within a multiprocessor system.